package com.openbravo.pos.util;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxEditor;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.JToolBar.Separator;
import javax.swing.JViewport;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileFilter;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JRImageMapRenderer;
import net.sf.jasperreports.engine.JRLineBox;
import net.sf.jasperreports.engine.JRPrintAnchorIndex;
import net.sf.jasperreports.engine.JRPrintElement;
import net.sf.jasperreports.engine.JRPrintFrame;
import net.sf.jasperreports.engine.JRPrintHyperlink;
import net.sf.jasperreports.engine.JRPrintImage;
import net.sf.jasperreports.engine.JRPrintImageArea;
import net.sf.jasperreports.engine.JRPrintImageAreaHyperlink;
import net.sf.jasperreports.engine.JRPrintPage;
import net.sf.jasperreports.engine.JRRenderable;
import net.sf.jasperreports.engine.JRRuntimeException;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.export.JRGraphics2DExporter;
import net.sf.jasperreports.engine.export.JRGraphics2DExporterParameter;
import net.sf.jasperreports.engine.print.JRPrinterAWT;
import net.sf.jasperreports.engine.util.JRClassLoader;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.engine.util.JRProperties;
import net.sf.jasperreports.engine.xml.JRPrintXmlLoader;
import net.sf.jasperreports.view.JRHyperlinkListener;
import net.sf.jasperreports.view.JRSaveContributor;
import net.sf.jasperreports.view.save.JRPrintSaveContributor;

public class JRViewer300 extends JPanel
  implements JRHyperlinkListener
{
  private static final long serialVersionUID = 10200L;
  public static final String VIEWER_RENDER_BUFFER_MAX_SIZE = "net.sf.jasperreports.viewer.render.buffer.max.size";
  protected static final int TYPE_FILE_NAME = 1;
  protected static final int TYPE_INPUT_STREAM = 2;
  protected static final int TYPE_OBJECT = 3;
  public static final int REPORT_RESOLUTION = 72;
  protected float MIN_ZOOM = 0.5F;
  protected float MAX_ZOOM = 10.0F;
  protected int[] zooms = { 50, 75, 100, 125, 150, 175, 200, 250, 400, 800 };
  protected int defaultZoomIndex = 2;
  protected int type = 1;
  protected boolean isXML = false;
  protected String reportFileName = null;
 public JasperPrint jasperPrint = null;
  private int pageIndex = 0;
  private boolean pageError;
  protected float zoom = 0.0F;
  private JRGraphics2DExporter exporter = null;
  private int screenResolution = 72;
  protected float realZoom = 0.0F;
  private DecimalFormat zoomDecimalFormat = new DecimalFormat("#.##");
  private ResourceBundle resourceBundle = null;
  private int downX = 0;
  private int downY = 0;
  private List hyperlinkListeners = new ArrayList();
  private Map linksMap = new HashMap();
  private MouseListener mouseListener = new MouseAdapter()
  {
    public void mouseClicked(MouseEvent paramMouseEvent)
    {
      JRViewer300.this.hyperlinkClicked(paramMouseEvent);
    }
  };
  protected KeyListener keyNavigationListener = new KeyListener()
  {
    public void keyTyped(KeyEvent paramKeyEvent)
    {
    }

    public void keyPressed(KeyEvent paramKeyEvent)
    {
      JRViewer300.this.keyNavigate(paramKeyEvent);
    }

    public void keyReleased(KeyEvent paramKeyEvent)
    {
    }
  };
  protected List saveContributors = new ArrayList();
  protected File lastFolder = null;
  protected JRSaveContributor lastSaveContributor = null;
  protected JToggleButton btnActualSize;
  protected JButton btnFirst;
  protected JToggleButton btnFitPage;
  protected JToggleButton btnFitWidth;
  protected JButton btnLast;
  protected JButton btnNext;
  protected JButton btnPrevious;
  protected JButton btnPrint;
  protected JButton btnReload;
  protected JButton btnSave;
  protected JButton btnZoomIn;
  protected JButton btnZoomOut;
  protected JComboBox cmbZoom;
  private JLabel jLabel1;
  private JPanel jPanel4;
  private JPanel jPanel5;
  private JPanel jPanel6;
  private JPanel jPanel7;
  private JPanel jPanel8;
  private JPanel jPanel9;
  private JToolBar.Separator jSeparator1;
  private JToolBar.Separator jSeparator2;
  private JToolBar.Separator jSeparator3;
  private JToolBar.Separator jSeparator4;
  private JToolBar jToolBar1;
  private PageRenderer lblPage;
  protected JLabel lblStatus;
  private JPanel pnlInScroll;
  private JPanel pnlLinks;
  private JPanel pnlMain;
  private JPanel pnlPage;
  private JScrollPane scrollPane;
  protected JTextField txtGoTo;

  public JRViewer300(String paramString, boolean paramBoolean)
    throws JRException
  {
    this(paramString, paramBoolean, null);
  }

  public JRViewer300(InputStream paramInputStream, boolean paramBoolean)
    throws JRException
  {
    this(paramInputStream, paramBoolean, null);
  }

  public JRViewer300(JasperPrint paramJasperPrint)
  {
    this(paramJasperPrint, null);
  }

  public JRViewer300(String paramString, boolean paramBoolean, Locale paramLocale)
    throws JRException
  {
    this(paramString, paramBoolean, paramLocale, null);
  }

  public JRViewer300(InputStream paramInputStream, boolean paramBoolean, Locale paramLocale)
    throws JRException
  {
    this(paramInputStream, paramBoolean, paramLocale, null);
  }

  public JRViewer300(JasperPrint paramJasperPrint, Locale paramLocale)
  {
    this(paramJasperPrint, paramLocale, null);
  }

  public JRViewer300(String paramString, boolean paramBoolean, Locale paramLocale, ResourceBundle paramResourceBundle)
    throws JRException
  {
    initResources(paramLocale, paramResourceBundle);
    setScreenDetails();
    setZooms();
    initComponents();
    loadReport(paramString, paramBoolean);
    this.cmbZoom.setSelectedIndex(this.defaultZoomIndex);
    initSaveContributors();
    addHyperlinkListener(this);
  }

  public JRViewer300(InputStream paramInputStream, boolean paramBoolean, Locale paramLocale, ResourceBundle paramResourceBundle)
    throws JRException
  {
    initResources(paramLocale, paramResourceBundle);
    setScreenDetails();
    setZooms();
    initComponents();
    loadReport(paramInputStream, paramBoolean);
    this.cmbZoom.setSelectedIndex(this.defaultZoomIndex);
    initSaveContributors();
    addHyperlinkListener(this);
  }

  public JRViewer300(JasperPrint paramJasperPrint, Locale paramLocale, ResourceBundle paramResourceBundle)
  {
    initResources(paramLocale, paramResourceBundle);
    setScreenDetails();
    setZooms();
    initComponents();
    loadReport(paramJasperPrint);
    this.cmbZoom.setSelectedIndex(this.defaultZoomIndex);
    initSaveContributors();
    addHyperlinkListener(this);
  }

  public void loadJasperPrint(JasperPrint paramJasperPrint)
  {
    loadReport(paramJasperPrint);
    setZoomRatio(this.zooms[this.defaultZoomIndex] / 100.0F);
    cmbZoomItemStateChanged(null);
    refreshPage();
  }

  private void setScreenDetails()
  {
    this.screenResolution = Toolkit.getDefaultToolkit().getScreenResolution();
  }

  public void clear()
  {
    emptyContainer(this);
    this.jasperPrint = null;
  }

  protected void setZooms()
  {
  }

  public void addSaveContributor(JRSaveContributor paramJRSaveContributor)
  {
    this.saveContributors.add(paramJRSaveContributor);
  }

  public void removeSaveContributor(JRSaveContributor paramJRSaveContributor)
  {
    this.saveContributors.remove(paramJRSaveContributor);
  }

  public JRSaveContributor[] getSaveContributors()
  {
    return (JRSaveContributor[])(JRSaveContributor[])this.saveContributors.toArray(new JRSaveContributor[this.saveContributors.size()]);
  }

  public void setSaveContributors(JRSaveContributor[] paramArrayOfJRSaveContributor)
  {
    this.saveContributors = new ArrayList();
    if (paramArrayOfJRSaveContributor != null)
      this.saveContributors.addAll(Arrays.asList(paramArrayOfJRSaveContributor));
  }

  public void addHyperlinkListener(JRHyperlinkListener paramJRHyperlinkListener)
  {
    this.hyperlinkListeners.add(paramJRHyperlinkListener);
  }

  public void removeHyperlinkListener(JRHyperlinkListener paramJRHyperlinkListener)
  {
    this.hyperlinkListeners.remove(paramJRHyperlinkListener);
  }

  public JRHyperlinkListener[] getHyperlinkListeners()
  {
    return (JRHyperlinkListener[])(JRHyperlinkListener[])this.hyperlinkListeners.toArray(new JRHyperlinkListener[this.hyperlinkListeners.size()]);
  }

  protected void initResources(Locale paramLocale, ResourceBundle paramResourceBundle)
  {
    if (paramLocale != null)
      setLocale(paramLocale);
    else
      setLocale(Locale.getDefault());
    if (paramResourceBundle == null)
      this.resourceBundle = ResourceBundle.getBundle("net/sf/jasperreports/view/viewer", getLocale());
    else
      this.resourceBundle = paramResourceBundle;
  }

  protected String getBundleString(String paramString)
  {
    return this.resourceBundle.getString(paramString);
  }

  protected void initSaveContributors()
  {
    String[] arrayOfString = { "net.sf.jasperreports.view.save.JRPrintSaveContributor", "net.sf.jasperreports.view.save.JRPdfSaveContributor", "net.sf.jasperreports.view.save.JRRtfSaveContributor", "net.sf.jasperreports.view.save.JROdtSaveContributor", "net.sf.jasperreports.view.save.JRHtmlSaveContributor", "net.sf.jasperreports.view.save.JRSingleSheetXlsSaveContributor", "net.sf.jasperreports.view.save.JRMultipleSheetsXlsSaveContributor", "net.sf.jasperreports.view.save.JRCsvSaveContributor", "net.sf.jasperreports.view.save.JRXmlSaveContributor", "net.sf.jasperreports.view.save.JREmbeddedImagesXmlSaveContributor" };
    for (int i = 0; i < arrayOfString.length; i++)
      try
      {
        Class localClass = JRClassLoader.loadClassForName(arrayOfString[i]);
        Constructor localConstructor = localClass.getConstructor(new Class[] { Locale.class, ResourceBundle.class });
        JRSaveContributor localJRSaveContributor = (JRSaveContributor)localConstructor.newInstance(new Object[] { getLocale(), this.resourceBundle });
        this.saveContributors.add(localJRSaveContributor);
      }
      catch (Exception localException)
      {
      }
  }

  public void gotoHyperlink(JRPrintHyperlink paramJRPrintHyperlink)
  {
    Object localObject1;
    Object localObject2;
    switch (paramJRPrintHyperlink.getHyperlinkType())
    {
    case 2:
      if (!isOnlyHyperlinkListener())
        break;
      System.out.println("Hyperlink reference : " + paramJRPrintHyperlink.getHyperlinkReference());
      System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
      break;
    case 3:
      if (paramJRPrintHyperlink.getHyperlinkAnchor() == null)
        break;
      Map localMap = this.jasperPrint.getAnchorIndexes();
      localObject1 = (JRPrintAnchorIndex)localMap.get(paramJRPrintHyperlink.getHyperlinkAnchor());
      if (((JRPrintAnchorIndex)localObject1).getPageIndex() != this.pageIndex)
      {
        setPageIndex(((JRPrintAnchorIndex)localObject1).getPageIndex());
        refreshPage();
      }
      localObject2 = this.pnlInScroll.getParent();
      if ((localObject2 instanceof JViewport))
      {
        JViewport localJViewport = (JViewport)localObject2;
        int j = (int)(((JRPrintAnchorIndex)localObject1).getElementAbsoluteX() * this.realZoom);
        int k = (int)(((JRPrintAnchorIndex)localObject1).getElementAbsoluteY() * this.realZoom);
        int m = this.pnlInScroll.getWidth() - localJViewport.getWidth();
        int n = this.pnlInScroll.getHeight() - localJViewport.getHeight();
        if (j < 0)
          j = 0;
        if (j > m)
          j = m;
        if (k < 0)
          k = 0;
        if (k > n)
          k = n;
        localJViewport.setViewPosition(new Point(j, k));
      }
      break;
    case 4:
      int i = this.pageIndex + 1;
      if (paramJRPrintHyperlink.getHyperlinkPage() != null)
        i = paramJRPrintHyperlink.getHyperlinkPage().intValue();
      if ((i < 1) || (i > this.jasperPrint.getPages().size()) || (i == this.pageIndex + 1))
        break;
      setPageIndex(i - 1);
      refreshPage();
      localObject1 = this.pnlInScroll.getParent();
      if ((localObject1 instanceof JViewport))
      {
        localObject2 = (JViewport)localObject1;
        ((JViewport)localObject2).setViewPosition(new Point(0, 0));
      }
      break;
    case 5:
      if (!isOnlyHyperlinkListener())
        break;
      System.out.println("Hyperlink reference : " + paramJRPrintHyperlink.getHyperlinkReference());
      System.out.println("Hyperlink anchor    : " + paramJRPrintHyperlink.getHyperlinkAnchor());
      System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
      break;
    case 6:
      if (!isOnlyHyperlinkListener())
        break;
      System.out.println("Hyperlink reference : " + paramJRPrintHyperlink.getHyperlinkReference());
      System.out.println("Hyperlink page      : " + paramJRPrintHyperlink.getHyperlinkPage());
      System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
      break;
    case 7:
      if (!isOnlyHyperlinkListener())
        break;
      System.out.println("Hyperlink of type " + paramJRPrintHyperlink.getLinkType());
      System.out.println("Implement your own JRHyperlinkListener to manage this type of event.");
      break;
    case 1:
    }
  }

  protected boolean isOnlyHyperlinkListener()
  {
    int i;
    if (this.hyperlinkListeners == null)
    {
      i = 0;
    }
    else
    {
      i = this.hyperlinkListeners.size();
      if (this.hyperlinkListeners.contains(this))
        i--;
    }
    return i == 0;
  }

  private void initComponents()
  {
    this.pnlMain = new JPanel();
    this.scrollPane = new JScrollPane();
    this.scrollPane.getHorizontalScrollBar().setUnitIncrement(5);
    this.scrollPane.getVerticalScrollBar().setUnitIncrement(5);
    this.pnlInScroll = new JPanel();
    this.pnlPage = new JPanel();
    this.jPanel4 = new JPanel();
    this.pnlLinks = new JPanel();
    this.jPanel5 = new JPanel();
    this.jPanel6 = new JPanel();
    this.jPanel7 = new JPanel();
    this.jPanel8 = new JPanel();
    this.jLabel1 = new JLabel();
    this.jPanel9 = new JPanel();
    this.lblPage = new PageRenderer(this);
    this.jToolBar1 = new JToolBar();
    this.btnSave = new JButton();
    this.btnPrint = new JButton();
    this.btnReload = new JButton();
    this.jSeparator1 = new JToolBar.Separator();
    this.btnActualSize = new JToggleButton();
    this.btnFitPage = new JToggleButton();
    this.btnFitWidth = new JToggleButton();
    this.jSeparator2 = new JToolBar.Separator();
    this.btnZoomIn = new JButton();
    this.cmbZoom = new JComboBox();
    DefaultComboBoxModel localDefaultComboBoxModel = new DefaultComboBoxModel();
    for (int i = 0; i < this.zooms.length; i++)
      localDefaultComboBoxModel.addElement("" + this.zooms[i] + "%");
    this.cmbZoom.setModel(localDefaultComboBoxModel);
    this.btnZoomOut = new JButton();
    this.jSeparator3 = new JToolBar.Separator();
    this.btnFirst = new JButton();
    this.btnPrevious = new JButton();
    this.txtGoTo = new JTextField();
    this.btnNext = new JButton();
    this.btnLast = new JButton();
    this.jSeparator4 = new JToolBar.Separator();
    this.lblStatus = new JLabel();
    setMinimumSize(new Dimension(450, 150));
    setPreferredSize(new Dimension(450, 150));
    setLayout(new BorderLayout());
    this.pnlMain.addComponentListener(new ComponentAdapter()
    {
      public void componentResized(ComponentEvent paramComponentEvent)
      {
        JRViewer300.this.pnlMainComponentResized(paramComponentEvent);
      }
    });
    this.pnlMain.setLayout(new BorderLayout());
    this.scrollPane.setHorizontalScrollBarPolicy(32);
    this.scrollPane.setVerticalScrollBarPolicy(22);
    this.pnlInScroll.setLayout(new GridBagLayout());
    this.pnlPage.setMinimumSize(new Dimension(100, 100));
    this.pnlPage.setPreferredSize(new Dimension(100, 100));
    this.pnlPage.setLayout(new BorderLayout());
    this.jPanel4.setMinimumSize(new Dimension(100, 120));
    this.jPanel4.setPreferredSize(new Dimension(100, 120));
    this.jPanel4.setLayout(new GridBagLayout());
    this.pnlLinks.setMinimumSize(new Dimension(5, 5));
    this.pnlLinks.setOpaque(false);
    this.pnlLinks.setPreferredSize(new Dimension(5, 5));
    this.pnlLinks.addMouseListener(new MouseAdapter()
    {
      public void mousePressed(MouseEvent paramMouseEvent)
      {
        JRViewer300.this.pnlLinksMousePressed(paramMouseEvent);
      }

      public void mouseReleased(MouseEvent paramMouseEvent)
      {
        JRViewer300.this.pnlLinksMouseReleased(paramMouseEvent);
      }
    });
    this.pnlLinks.addMouseMotionListener(new MouseMotionAdapter()
    {
      public void mouseDragged(MouseEvent paramMouseEvent)
      {
        JRViewer300.this.pnlLinksMouseDragged(paramMouseEvent);
      }
    });
    this.pnlLinks.setLayout(null);
    GridBagConstraints localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 0;
    localGridBagConstraints.gridy = 0;
    localGridBagConstraints.gridwidth = 2;
    localGridBagConstraints.gridheight = 2;
    localGridBagConstraints.fill = 1;
    this.jPanel4.add(this.pnlLinks, localGridBagConstraints);
    this.jPanel5.setBackground(Color.gray);
    this.jPanel5.setMinimumSize(new Dimension(5, 5));
    this.jPanel5.setPreferredSize(new Dimension(5, 5));
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 2;
    localGridBagConstraints.gridy = 1;
    localGridBagConstraints.fill = 3;
    this.jPanel4.add(this.jPanel5, localGridBagConstraints);
    this.jPanel6.setMinimumSize(new Dimension(5, 5));
    this.jPanel6.setPreferredSize(new Dimension(5, 5));
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 0;
    localGridBagConstraints.gridy = 2;
    this.jPanel4.add(this.jPanel6, localGridBagConstraints);
    this.jPanel7.setBackground(Color.gray);
    this.jPanel7.setMinimumSize(new Dimension(5, 5));
    this.jPanel7.setPreferredSize(new Dimension(5, 5));
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 1;
    localGridBagConstraints.gridy = 2;
    localGridBagConstraints.fill = 2;
    this.jPanel4.add(this.jPanel7, localGridBagConstraints);
    this.jPanel8.setBackground(Color.gray);
    this.jPanel8.setMinimumSize(new Dimension(5, 5));
    this.jPanel8.setPreferredSize(new Dimension(5, 5));
    this.jLabel1.setText("jLabel1");
    this.jPanel8.add(this.jLabel1);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 2;
    localGridBagConstraints.gridy = 2;
    this.jPanel4.add(this.jPanel8, localGridBagConstraints);
    this.jPanel9.setMinimumSize(new Dimension(5, 5));
    this.jPanel9.setPreferredSize(new Dimension(5, 5));
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 2;
    localGridBagConstraints.gridy = 0;
    this.jPanel4.add(this.jPanel9, localGridBagConstraints);
    this.lblPage.setBackground(Color.white);
    this.lblPage.setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0)));
    this.lblPage.setOpaque(true);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 0;
    localGridBagConstraints.gridy = 0;
    localGridBagConstraints.gridwidth = 2;
    localGridBagConstraints.gridheight = 2;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    this.jPanel4.add(this.lblPage, localGridBagConstraints);
    this.pnlPage.add(this.jPanel4, "Center");
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.insets = new Insets(5, 5, 5, 5);
    this.pnlInScroll.add(this.pnlPage, localGridBagConstraints);
    this.scrollPane.setViewportView(this.pnlInScroll);
    this.pnlMain.add(this.scrollPane, "Center");
    this.jToolBar1.setFloatable(false);
    this.btnSave.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/filesave.png")));
    this.btnSave.setToolTipText(getBundleString("save"));
    this.btnSave.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.btnSaveActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.btnSave);
    this.btnPrint.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/yast_printer.png")));
    this.btnPrint.setToolTipText(getBundleString("print"));
    this.btnPrint.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.btnPrintActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.btnPrint);
    this.btnReload.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/reload.png")));
    this.btnReload.setToolTipText(getBundleString("reload"));
    this.btnReload.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.btnReloadActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.btnReload);
    this.jToolBar1.add(this.jSeparator1);
    this.btnActualSize.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/mime.png")));
    this.btnActualSize.setToolTipText(getBundleString("actual.size"));
    this.btnActualSize.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.btnActualSizeActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.btnActualSize);
    this.btnFitPage.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/mime2.png")));
    this.btnFitPage.setToolTipText(getBundleString("fit.page"));
    this.btnFitPage.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.btnFitPageActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.btnFitPage);
    this.btnFitWidth.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/mime3.png")));
    this.btnFitWidth.setToolTipText(getBundleString("fit.width"));
    this.btnFitWidth.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.btnFitWidthActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.btnFitWidth);
    this.jToolBar1.add(this.jSeparator2);
    this.btnZoomIn.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/viewmag+.png")));
    this.btnZoomIn.setToolTipText(getBundleString("zoom.in"));
    this.btnZoomIn.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.btnZoomInActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.btnZoomIn);
    this.cmbZoom.setEditable(true);
    this.cmbZoom.setToolTipText(getBundleString("zoom.ratio"));
    this.cmbZoom.setMaximumSize(new Dimension(80, 23));
    this.cmbZoom.setMinimumSize(new Dimension(80, 23));
    this.cmbZoom.setPreferredSize(new Dimension(80, 23));
    this.cmbZoom.addItemListener(new ItemListener()
    {
      public void itemStateChanged(ItemEvent paramItemEvent)
      {
        JRViewer300.this.cmbZoomItemStateChanged(paramItemEvent);
      }
    });
    this.cmbZoom.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.cmbZoomActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.cmbZoom);
    this.btnZoomOut.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/viewmag-.png")));
    this.btnZoomOut.setToolTipText(getBundleString("zoom.out"));
    this.btnZoomOut.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.btnZoomOutActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.btnZoomOut);
    this.jToolBar1.add(this.jSeparator3);
    this.btnFirst.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/2leftarrow.png")));
    this.btnFirst.setToolTipText(getBundleString("first.page"));
    this.btnFirst.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.btnFirstActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.btnFirst);
    this.btnPrevious.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/1leftarrow.png")));
    this.btnPrevious.setToolTipText(getBundleString("previous.page"));
    this.btnPrevious.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.btnPreviousActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.btnPrevious);
    this.txtGoTo.setToolTipText(getBundleString("go.to.page"));
    this.txtGoTo.setMaximumSize(new Dimension(40, 23));
    this.txtGoTo.setMinimumSize(new Dimension(40, 23));
    this.txtGoTo.setPreferredSize(new Dimension(40, 23));
    this.txtGoTo.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.txtGoToActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.txtGoTo);
    this.btnNext.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/1rightarrow.png")));
    this.btnNext.setToolTipText(getBundleString("next.page"));
    this.btnNext.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.btnNextActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.btnNext);
    this.btnLast.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/2rightarrow.png")));
    this.btnLast.setToolTipText(getBundleString("last.page"));
    this.btnLast.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JRViewer300.this.btnLastActionPerformed(paramActionEvent);
      }
    });
    this.jToolBar1.add(this.btnLast);
    this.jToolBar1.add(this.jSeparator4);
    this.lblStatus.setText("Page i of n");
    this.jToolBar1.add(this.lblStatus);
    this.pnlMain.add(this.jToolBar1, "North");
    add(this.pnlMain, "Center");
  }

  void txtGoToActionPerformed(ActionEvent paramActionEvent)
  {
    try
    {
      int i = Integer.parseInt(this.txtGoTo.getText());
      if ((i != this.pageIndex + 1) && (i > 0) && (i <= this.jasperPrint.getPages().size()))
      {
        setPageIndex(i - 1);
        refreshPage();
      }
    }
    catch (NumberFormatException localNumberFormatException)
    {
    }
  }

  void cmbZoomItemStateChanged(ItemEvent paramItemEvent)
  {
    this.btnActualSize.setSelected(false);
    this.btnFitPage.setSelected(false);
    this.btnFitWidth.setSelected(false);
  }

  void pnlMainComponentResized(ComponentEvent paramComponentEvent)
  {
    if (this.btnFitPage.isSelected())
    {
      fitPage();
      this.btnFitPage.setSelected(true);
    }
    else if (this.btnFitWidth.isSelected())
    {
      setRealZoomRatio(((float)this.pnlInScroll.getVisibleRect().getWidth() - 20.0F) / this.jasperPrint.getPageWidth());
      this.btnFitWidth.setSelected(true);
    }
  }

  void btnActualSizeActionPerformed(ActionEvent paramActionEvent)
  {
    if (this.btnActualSize.isSelected())
    {
      this.btnFitPage.setSelected(false);
      this.btnFitWidth.setSelected(false);
      this.cmbZoom.setSelectedIndex(-1);
      setZoomRatio(1.0F);
      this.btnActualSize.setSelected(true);
    }
  }

  void btnFitWidthActionPerformed(ActionEvent paramActionEvent)
  {
    if (this.btnFitWidth.isSelected())
    {
      this.btnActualSize.setSelected(false);
      this.btnFitPage.setSelected(false);
      this.cmbZoom.setSelectedIndex(-1);
      setRealZoomRatio(((float)this.pnlInScroll.getVisibleRect().getWidth() - 20.0F) / this.jasperPrint.getPageWidth());
      this.btnFitWidth.setSelected(true);
    }
  }

  void btnFitPageActionPerformed(ActionEvent paramActionEvent)
  {
    if (this.btnFitPage.isSelected())
    {
      this.btnActualSize.setSelected(false);
      this.btnFitWidth.setSelected(false);
      this.cmbZoom.setSelectedIndex(-1);
      fitPage();
      this.btnFitPage.setSelected(true);
    }
  }

  void btnSaveActionPerformed(ActionEvent paramActionEvent)
  {
    JFileChooser localJFileChooser = new JFileChooser();
    localJFileChooser.setLocale(getLocale());
    localJFileChooser.updateUI();
    for (int i = 0; i < this.saveContributors.size(); i++)
      localJFileChooser.addChoosableFileFilter((JRSaveContributor)this.saveContributors.get(i));
    if (this.saveContributors.contains(this.lastSaveContributor))
      localJFileChooser.setFileFilter(this.lastSaveContributor);
    else if (this.saveContributors.size() > 0)
      localJFileChooser.setFileFilter((JRSaveContributor)this.saveContributors.get(0));
    if (this.lastFolder != null)
      localJFileChooser.setCurrentDirectory(this.lastFolder);
    int i = localJFileChooser.showSaveDialog(this);
    if (i == 0)
    {
      FileFilter localFileFilter = localJFileChooser.getFileFilter();
      File localFile = localJFileChooser.getSelectedFile();
      this.lastFolder = localFile.getParentFile();
      Object localObject = null;
      if ((localFileFilter instanceof JRSaveContributor))
      {
        localObject = (JRSaveContributor)localFileFilter;
      }
      else
      {
        int j = 0;
        while ((localObject == null) && (j < this.saveContributors.size()))
        {
          localObject = (JRSaveContributor)this.saveContributors.get(j++);
          if (((JRSaveContributor)localObject).accept(localFile))
            continue;
          localObject = null;
        }
        if (localObject == null)
          localObject = new JRPrintSaveContributor(getLocale(), this.resourceBundle);
      }
      this.lastSaveContributor = ((JRSaveContributor)localObject);
      try
      {
        ((JRSaveContributor)localObject).save(this.jasperPrint, localFile);
      }
      catch (JRException localJRException)
      {
        localJRException.printStackTrace();
        JOptionPane.showMessageDialog(this, getBundleString("error.saving"));
      }
    }
  }

  void pnlLinksMouseDragged(MouseEvent paramMouseEvent)
  {
    Container localContainer = this.pnlInScroll.getParent();
    if ((localContainer instanceof JViewport))
    {
      JViewport localJViewport = (JViewport)localContainer;
      Point localPoint = localJViewport.getViewPosition();
      int i = localPoint.x - (paramMouseEvent.getX() - this.downX);
      int j = localPoint.y - (paramMouseEvent.getY() - this.downY);
      int k = this.pnlInScroll.getWidth() - localJViewport.getWidth();
      int m = this.pnlInScroll.getHeight() - localJViewport.getHeight();
      if (i < 0)
        i = 0;
      if (i > k)
        i = k;
      if (j < 0)
        j = 0;
      if (j > m)
        j = m;
      localJViewport.setViewPosition(new Point(i, j));
    }
  }

  void pnlLinksMouseReleased(MouseEvent paramMouseEvent)
  {
    this.pnlLinks.setCursor(new Cursor(0));
  }

  void pnlLinksMousePressed(MouseEvent paramMouseEvent)
  {
    this.pnlLinks.setCursor(new Cursor(13));
    this.downX = paramMouseEvent.getX();
    this.downY = paramMouseEvent.getY();
  }

  void btnPrintActionPerformed(ActionEvent paramActionEvent)
  {
    SwingUtilities.invokeLater(new Runnable()
    {
      public void run()
      {
        try
        {
          JRViewer300.this.btnPrint.setEnabled(false);
          JRViewer300.this.setCursor(Cursor.getPredefinedCursor(3));
          JasperPrintManager.printReport(JRViewer300.this.jasperPrint, true);
        }
        catch (Exception localException)
        {
          localException.printStackTrace();
          JOptionPane.showMessageDialog(JRViewer300.this, JRViewer300.this.getBundleString("error.printing"));
        }
        finally
        {
          JRViewer300.this.setCursor(Cursor.getPredefinedCursor(0));
          JRViewer300.this.btnPrint.setEnabled(true);
        }
      }
    });
  }

  void btnLastActionPerformed(ActionEvent paramActionEvent)
  {
    setPageIndex(this.jasperPrint.getPages().size() - 1);
    refreshPage();
  }

  void btnNextActionPerformed(ActionEvent paramActionEvent)
  {
    setPageIndex(this.pageIndex + 1);
    refreshPage();
  }

  void btnPreviousActionPerformed(ActionEvent paramActionEvent)
  {
    setPageIndex(this.pageIndex - 1);
    refreshPage();
  }

  void btnFirstActionPerformed(ActionEvent paramActionEvent)
  {
    setPageIndex(0);
    refreshPage();
  }

  void btnReloadActionPerformed(ActionEvent paramActionEvent)
  {
    if (this.type == 1)
    {
      try
      {
        loadReport(this.reportFileName, this.isXML);
      }
      catch (JRException localJRException)
      {
        localJRException.printStackTrace();
        this.jasperPrint = null;
        setPageIndex(0);
        refreshPage();
        JOptionPane.showMessageDialog(this, getBundleString("error.loading"));
      }
      forceRefresh();
    }
  }

  protected void forceRefresh()
  {
    this.zoom = 0.0F;
    this.realZoom = 0.0F;
    setZoomRatio(1.0F);
  }

  void btnZoomInActionPerformed(ActionEvent paramActionEvent)
  {
    this.btnActualSize.setSelected(false);
    this.btnFitPage.setSelected(false);
    this.btnFitWidth.setSelected(false);
    int i = (int)(100.0F * getZoomRatio());
    int j = Arrays.binarySearch(this.zooms, i);
    if (j < 0)
      setZoomRatio(this.zooms[(-j - 1)] / 100.0F);
    else if (j < this.cmbZoom.getModel().getSize() - 1)
      setZoomRatio(this.zooms[(j + 1)] / 100.0F);
  }

  void btnZoomOutActionPerformed(ActionEvent paramActionEvent)
  {
    this.btnActualSize.setSelected(false);
    this.btnFitPage.setSelected(false);
    this.btnFitWidth.setSelected(false);
    int i = (int)(100.0F * getZoomRatio());
    int j = Arrays.binarySearch(this.zooms, i);
    if (j > 0)
      setZoomRatio(this.zooms[(j - 1)] / 100.0F);
    else if (j < -1)
      setZoomRatio(this.zooms[(-j - 2)] / 100.0F);
  }

  void cmbZoomActionPerformed(ActionEvent paramActionEvent)
  {
    float f = getZoomRatio();
    if (f < this.MIN_ZOOM)
      f = this.MIN_ZOOM;
    if (f > this.MAX_ZOOM)
      f = this.MAX_ZOOM;
    setZoomRatio(f);
  }

  void hyperlinkClicked(MouseEvent paramMouseEvent)
  {
    JPanel localJPanel = (JPanel)paramMouseEvent.getSource();
    JRPrintHyperlink localJRPrintHyperlink = (JRPrintHyperlink)this.linksMap.get(localJPanel);
    hyperlinkClicked(localJRPrintHyperlink);
  }

  protected void hyperlinkClicked(JRPrintHyperlink paramJRPrintHyperlink)
  {
    try
    {
      JRHyperlinkListener localJRHyperlinkListener = null;
      for (int i = 0; i < this.hyperlinkListeners.size(); i++)
      {
        localJRHyperlinkListener = (JRHyperlinkListener)this.hyperlinkListeners.get(i);
        localJRHyperlinkListener.gotoHyperlink(paramJRPrintHyperlink);
      }
    }
    catch (JRException localJRException)
    {
      localJRException.printStackTrace();
      JOptionPane.showMessageDialog(this, getBundleString("error.hyperlink"));
    }
  }

  public int getPageIndex()
  {
    return this.pageIndex;
  }

  private void setPageIndex(int paramInt)
  {
    if ((this.jasperPrint != null) && (this.jasperPrint.getPages() != null) && (this.jasperPrint.getPages().size() > 0))
    {
      if ((paramInt >= 0) && (paramInt < this.jasperPrint.getPages().size()))
      {
        this.pageIndex = paramInt;
        this.pageError = false;
        this.btnFirst.setEnabled(this.pageIndex > 0);
        this.btnPrevious.setEnabled(this.pageIndex > 0);
        this.btnNext.setEnabled(this.pageIndex < this.jasperPrint.getPages().size() - 1);
        this.btnLast.setEnabled(this.pageIndex < this.jasperPrint.getPages().size() - 1);
        this.txtGoTo.setEnabled((this.btnFirst.isEnabled()) || (this.btnLast.isEnabled()));
        this.txtGoTo.setText("" + (this.pageIndex + 1));
        this.lblStatus.setText(MessageFormat.format(getBundleString("page"), new Object[] { new Integer(this.pageIndex + 1), new Integer(this.jasperPrint.getPages().size()) }));
      }
    }
    else
    {
      this.btnFirst.setEnabled(false);
      this.btnPrevious.setEnabled(false);
      this.btnNext.setEnabled(false);
      this.btnLast.setEnabled(false);
      this.txtGoTo.setEnabled(false);
      this.txtGoTo.setText("");
      this.lblStatus.setText("");
    }
  }

  protected void loadReport(String paramString, boolean paramBoolean)
    throws JRException
  {
    if (paramBoolean)
      this.jasperPrint = JRPrintXmlLoader.load(paramString);
    else
      this.jasperPrint = ((JasperPrint)JRLoader.loadObject(paramString));
    this.type = 1;
    this.isXML = paramBoolean;
    this.reportFileName = paramString;
    this.btnReload.setEnabled(true);
    setPageIndex(0);
  }

  protected void loadReport(InputStream paramInputStream, boolean paramBoolean)
    throws JRException
  {
    if (paramBoolean)
      this.jasperPrint = JRPrintXmlLoader.load(paramInputStream);
    else
      this.jasperPrint = ((JasperPrint)JRLoader.loadObject(paramInputStream));
    this.type = 2;
    this.isXML = paramBoolean;
    this.btnReload.setEnabled(false);
    setPageIndex(0);
  }

  protected void loadReport(JasperPrint paramJasperPrint)
  {
    this.jasperPrint = paramJasperPrint;
    this.type = 3;
    this.isXML = false;
    this.btnReload.setEnabled(false);
    setPageIndex(0);
  }

  protected void refreshPage()
  {
	  
	 
    if ((this.jasperPrint == null) || (this.jasperPrint.getPages() == null) || (this.jasperPrint.getPages().size() == 0))
    {
      this.pnlPage.setVisible(false);
      this.btnSave.setEnabled(false);
      this.btnPrint.setEnabled(false);
      this.btnActualSize.setEnabled(false);
      this.btnFitPage.setEnabled(false);
      this.btnFitWidth.setEnabled(false);
      this.btnZoomIn.setEnabled(false);
      this.btnZoomOut.setEnabled(false);
      this.cmbZoom.setEnabled(false);
   //   return;
    }
//    if (this.jasperPrint != null)
//	  {
//	        JOptionPane.showMessageDialog(this, getBundleString("no.pages"));
//	      return;
//	  }
    this.pnlPage.setVisible(true);
    this.btnSave.setEnabled(true);
    this.btnPrint.setEnabled(true);
    this.btnActualSize.setEnabled(true);
    this.btnFitPage.setEnabled(true);
    this.btnFitWidth.setEnabled(true);
    this.btnZoomIn.setEnabled(this.zoom < this.MAX_ZOOM);
    this.btnZoomOut.setEnabled(this.zoom > this.MIN_ZOOM);
    this.cmbZoom.setEnabled(true);
  //  if (this.jasperPrint != null) //ati
     if(this.jasperPrint!=null  )
    {
    Dimension localDimension = new Dimension((int)(this.jasperPrint.getPageWidth() * this.realZoom) + 8, (int)(this.jasperPrint.getPageHeight() * this.realZoom) + 8);
    this.pnlPage.setMaximumSize(localDimension);
    this.pnlPage.setMinimumSize(localDimension);
    this.pnlPage.setPreferredSize(localDimension);
    }
    long l1 = JRProperties.getLongProperty("net.sf.jasperreports.viewer.render.buffer.max.size");
    boolean bool;
    if (l1 <= 0L)
    {
      bool = false;
    }
    else
    {
      long l2 = JRPrinterAWT.getImageSize(this.jasperPrint, this.realZoom);
      bool = l2 <= l1;
    }
    this.lblPage.setRenderImage(bool);
    if (bool)
      setPageImage();
    this.pnlLinks.removeAll();
    this.linksMap = new HashMap();
    if(this.jasperPrint!=null  )//ati
    createHyperlinks();
    if (!bool)
    {
      this.lblPage.setIcon(null);
      this.pnlMain.validate();
      this.pnlMain.repaint();
    }
    
    
    
  }

  protected void setPageImage()
  {
    Image localImage;
    if (this.pageError)
      localImage = getPageErrorImage();
    else
      try
      {
        localImage = JasperPrintManager.printPageToImage(this.jasperPrint, this.pageIndex, this.realZoom);
      }
      catch (Exception localException)
      {
        this.pageError = true;
        localException.printStackTrace();
        localImage = getPageErrorImage();
        JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("net/sf/jasperreports/view/viewer").getString("error.displaying"));
      }
    ImageIcon localImageIcon = new ImageIcon(localImage);
    this.lblPage.setIcon(localImageIcon);
  }

  protected Image getPageErrorImage()
  {
    BufferedImage localBufferedImage = new BufferedImage((int)(this.jasperPrint.getPageWidth() * this.realZoom) + 1, (int)(this.jasperPrint.getPageHeight() * this.realZoom) + 1, 1);
    Graphics2D localGraphics2D = (Graphics2D)localBufferedImage.getGraphics();
    AffineTransform localAffineTransform = new AffineTransform();
    localAffineTransform.scale(this.realZoom, this.realZoom);
    localGraphics2D.transform(localAffineTransform);
    drawPageError(localGraphics2D);
    return localBufferedImage;
  }
  @SuppressWarnings("rawtypes")
  protected void createHyperlinks()
  {
   
    try{//ati
	List localList = this.jasperPrint.getPages();
	if(localList.size()>0) //ati
	{
    JRPrintPage localJRPrintPage = (JRPrintPage)localList.get(this.pageIndex);
    createHyperlinks(localJRPrintPage.getElements(), 0, 0);
	}
    }catch(Exception e)
    {
    	e.printStackTrace();
    }
  }

  protected void createHyperlinks(List paramList, int paramInt1, int paramInt2)
  {
    if ((paramList != null) && (paramList.size() > 0))
    {
      Iterator localIterator = paramList.iterator();
      while (localIterator.hasNext())
      {
        JRPrintElement localJRPrintElement = (JRPrintElement)localIterator.next();
        JRImageMapRenderer localJRImageMapRenderer = null;
        if ((localJRPrintElement instanceof JRPrintImage))
        {
          JRRenderable localJRRenderable = ((JRPrintImage)localJRPrintElement).getRenderer();
          if ((localJRRenderable instanceof JRImageMapRenderer))
          {
            localJRImageMapRenderer = (JRImageMapRenderer)localJRRenderable;
            if (!localJRImageMapRenderer.hasImageAreaHyperlinks())
              localJRImageMapRenderer = null;
          }
        }
        int i = localJRImageMapRenderer != null ? 1 : 0;
        JRPrintHyperlink localJRPrintHyperlink = null;
        if ((localJRPrintElement instanceof JRPrintHyperlink))
          localJRPrintHyperlink = (JRPrintHyperlink)localJRPrintElement;
        int j = (i == 0) && (localJRPrintHyperlink != null) && (localJRPrintHyperlink.getHyperlinkType() != 1) ? 1 : 0;
        int k = (localJRPrintHyperlink != null) && (localJRPrintHyperlink.getHyperlinkTooltip() != null) ? 1 : 0;
        Object localObject1;
        if ((j != 0) || (i != 0) || (k != 0))
        {
          if (i != 0)
          {
            Rectangle localObject2 = new Rectangle(0, 0, localJRPrintElement.getWidth(), localJRPrintElement.getHeight());
            localObject1 = new ImageMapPanel((Rectangle)localObject2, localJRImageMapRenderer);
          }
          else
          {
            localObject1 = new JPanel();
            if (j != 0)
              ((JPanel)localObject1).addMouseListener(this.mouseListener);
          }
          if (j != 0)
            ((JPanel)localObject1).setCursor(new Cursor(12));
          ((JPanel)localObject1).setLocation((int)((localJRPrintElement.getX() + paramInt1) * this.realZoom), (int)((localJRPrintElement.getY() + paramInt2) * this.realZoom));
          ((JPanel)localObject1).setSize((int)(localJRPrintElement.getWidth() * this.realZoom), (int)(localJRPrintElement.getHeight() * this.realZoom));
          ((JPanel)localObject1).setOpaque(false);
          Object localObject2 = getHyperlinkTooltip(localJRPrintHyperlink);
          if ((localObject2 == null) && (i != 0))
            localObject2 = "";
          ((JPanel)localObject1).setToolTipText((String)localObject2);
          this.pnlLinks.add((Component)localObject1);
          this.linksMap.put(localObject1, localJRPrintElement);
        }
        if ((localJRPrintElement instanceof JRPrintFrame))
        {
          localObject1 = (JRPrintFrame)localJRPrintElement;
          int m = paramInt1 + ((JRPrintFrame)localObject1).getX() + ((JRPrintFrame)localObject1).getLineBox().getLeftPadding().intValue();
          int n = paramInt2 + ((JRPrintFrame)localObject1).getY() + ((JRPrintFrame)localObject1).getLineBox().getTopPadding().intValue();
          createHyperlinks(((JRPrintFrame)localObject1).getElements(), m, n);
        }
      }
    }
  }

  protected String getHyperlinkTooltip(JRPrintHyperlink paramJRPrintHyperlink)
  {
    String str = paramJRPrintHyperlink.getHyperlinkTooltip();
    if (str == null)
      str = getFallbackTooltip(paramJRPrintHyperlink);
    return str;
  }

  protected String getFallbackTooltip(JRPrintHyperlink paramJRPrintHyperlink)
  {
    String str = null;
    switch (paramJRPrintHyperlink.getHyperlinkType())
    {
    case 2:
      str = paramJRPrintHyperlink.getHyperlinkReference();
      break;
    case 3:
      if (paramJRPrintHyperlink.getHyperlinkAnchor() == null)
        break;
      str = "#" + paramJRPrintHyperlink.getHyperlinkAnchor();
      break;
    case 4:
      if (paramJRPrintHyperlink.getHyperlinkPage() == null)
        break;
      str = "#page " + paramJRPrintHyperlink.getHyperlinkPage();
      break;
    case 5:
      str = "";
      if (paramJRPrintHyperlink.getHyperlinkReference() != null)
        str = str + paramJRPrintHyperlink.getHyperlinkReference();
      if (paramJRPrintHyperlink.getHyperlinkAnchor() == null)
        break;
      str = str + "#" + paramJRPrintHyperlink.getHyperlinkAnchor();
      break;
    case 6:
      str = "";
      if (paramJRPrintHyperlink.getHyperlinkReference() != null)
        str = str + paramJRPrintHyperlink.getHyperlinkReference();
      if (paramJRPrintHyperlink.getHyperlinkPage() == null)
        break;
      str = str + "#page " + paramJRPrintHyperlink.getHyperlinkPage();
      break;
    }
    return str;
  }

  private void emptyContainer(Container paramContainer)
  {
    Component[] arrayOfComponent = paramContainer.getComponents();
    if (arrayOfComponent != null)
      for (int i = 0; i < arrayOfComponent.length; i++)
      {
        if (!(arrayOfComponent[i] instanceof Container))
          continue;
        emptyContainer((Container)arrayOfComponent[i]);
      }
    arrayOfComponent = null;
    paramContainer.removeAll();
    paramContainer = null;
  }

  private float getZoomRatio()
  {
    float f = this.zoom;
    try
    {
      f = this.zoomDecimalFormat.parse(String.valueOf(this.cmbZoom.getEditor().getItem())).floatValue() / 100.0F;
    }
    catch (ParseException localParseException)
    {
    }
    return f;
  }

  public void setZoomRatio(float paramFloat)
  {
    if (paramFloat > 0.0F)
    {
      this.cmbZoom.getEditor().setItem(this.zoomDecimalFormat.format(paramFloat * 100.0F) + "%");
      if (this.zoom != paramFloat)
      {
        this.zoom = paramFloat;
        this.realZoom = (this.zoom * this.screenResolution / 72.0F);
        refreshPage();
      }
    }
  }

  private void setRealZoomRatio(float paramFloat)
  {
    if ((paramFloat > 0.0F) && (this.realZoom != paramFloat))
    {
      this.zoom = (paramFloat * 72.0F / this.screenResolution);
      this.realZoom = paramFloat;
      this.cmbZoom.getEditor().setItem(this.zoomDecimalFormat.format(this.zoom * 100.0F) + "%");
      refreshPage();
    }
  }

  public void setFitWidthZoomRatio()
  {
    setRealZoomRatio(((float)this.pnlInScroll.getVisibleRect().getWidth() - 20.0F) / this.jasperPrint.getPageWidth());
  }

  public void setFitPageZoomRatio()
  {
    setRealZoomRatio(((float)this.pnlInScroll.getVisibleRect().getHeight() - 20.0F) / this.jasperPrint.getPageHeight());
  }

  protected JRGraphics2DExporter getGraphics2DExporter()
    throws JRException
  {
    return new JRGraphics2DExporter();
  }

  protected void paintPage(Graphics2D paramGraphics2D)
  {
    if (this.pageError)
    {
      paintPageError(paramGraphics2D);
      return;
    }
    try
    {
      if (this.exporter == null)
        this.exporter = getGraphics2DExporter();
      else
        this.exporter.reset();
      this.exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
      this.exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, paramGraphics2D.create());
      this.exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(this.pageIndex));
      this.exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(this.realZoom));
      this.exporter.setParameter(JRExporterParameter.OFFSET_X, new Integer(1));
      this.exporter.setParameter(JRExporterParameter.OFFSET_Y, new Integer(1));
      
      //ati
      try {
    	  this.exporter.exportReport();
	} catch (Exception e) {
		// TODO: handle exception
	}
     
    }
    catch (Exception localException)
    {
      this.pageError = true;
      localException.printStackTrace();
      paintPageError(paramGraphics2D);
      SwingUtilities.invokeLater(new Runnable()
      {
        public void run()
        {
          JOptionPane.showMessageDialog(JRViewer300.this, JRViewer300.this.getBundleString("error.displaying"));
        }
      });
    }
  }

  protected void paintPageError(Graphics2D paramGraphics2D)
  {
    AffineTransform localAffineTransform1 = paramGraphics2D.getTransform();
    AffineTransform localAffineTransform2 = new AffineTransform();
    localAffineTransform2.translate(1.0D, 1.0D);
    localAffineTransform2.scale(this.realZoom, this.realZoom);
    paramGraphics2D.transform(localAffineTransform2);
    try
    {
      drawPageError(paramGraphics2D);
    }
    finally
    {
      paramGraphics2D.setTransform(localAffineTransform1);
    }
  }

  protected void drawPageError(Graphics paramGraphics)
  {
    paramGraphics.setColor(Color.white);
    paramGraphics.fillRect(0, 0, this.jasperPrint.getPageWidth() + 1, this.jasperPrint.getPageHeight() + 1);
  }

  protected void keyNavigate(KeyEvent paramKeyEvent)
  {
    int i = 1;
    switch (paramKeyEvent.getKeyCode())
    {
    case 34:
    case 40:
      dnNavigate(paramKeyEvent);
      break;
    case 33:
    case 38:
      upNavigate(paramKeyEvent);
      break;
    case 36:
      homeEndNavigate(0);
      break;
    case 35:
      homeEndNavigate(this.jasperPrint.getPages().size() - 1);
      break;
    case 37:
    case 39:
    default:
      i = 0;
    }
    if (i != 0)
      refreshPage();
  }

  private void dnNavigate(KeyEvent paramKeyEvent)
  {
    int i = this.scrollPane.getVerticalScrollBar().getValue();
    this.scrollPane.dispatchEvent(paramKeyEvent);
    if (((this.scrollPane.getViewport().getHeight() > this.pnlPage.getHeight()) || (this.scrollPane.getVerticalScrollBar().getValue() == i)) && (this.pageIndex < this.jasperPrint.getPages().size() - 1))
    {
      setPageIndex(this.pageIndex + 1);
      if (this.scrollPane.isEnabled())
        this.scrollPane.getVerticalScrollBar().setValue(0);
    }
  }

  private void upNavigate(KeyEvent paramKeyEvent)
  {
    if (((this.scrollPane.getViewport().getHeight() > this.pnlPage.getHeight()) || (this.scrollPane.getVerticalScrollBar().getValue() == 0)) && (this.pageIndex > 0))
    {
      setPageIndex(this.pageIndex - 1);
      if (this.scrollPane.isEnabled())
        this.scrollPane.getVerticalScrollBar().setValue(this.scrollPane.getVerticalScrollBar().getMaximum());
    }
    else
    {
      this.scrollPane.dispatchEvent(paramKeyEvent);
    }
  }

  private void homeEndNavigate(int paramInt)
  {
    setPageIndex(paramInt);
    if (this.scrollPane.isEnabled())
      this.scrollPane.getVerticalScrollBar().setValue(0);
  }

  private void fitPage()
  {
    float f1 = ((float)this.pnlInScroll.getVisibleRect().getHeight() - 20.0F) / this.jasperPrint.getPageHeight();
    float f2 = ((float)this.pnlInScroll.getVisibleRect().getWidth() - 20.0F) / this.jasperPrint.getPageWidth();
    setRealZoomRatio(f1 < f2 ? f1 : f2);
  }

  class PageRenderer extends JLabel
  {
    private static final long serialVersionUID = 10200L;
    private boolean renderImage;
    JRViewer300 viewer = null;

    public PageRenderer(JRViewer300 arg2)
    {
      Object localObject;
      this.viewer = arg2;
    }

    public void paintComponent(Graphics paramGraphics)
    {
      if (isRenderImage())
        super.paintComponent(paramGraphics);
      else
      {
    	 if(jasperPrint!=null)//ati
        this.viewer.paintPage((Graphics2D)paramGraphics.create());
      }
    }

    public boolean isRenderImage()
    {
      return this.renderImage;
    }

    public void setRenderImage(boolean paramBoolean)
    {
      this.renderImage = paramBoolean;
    }
  }

  protected class ImageMapPanel extends JPanel
    implements MouseListener, MouseMotionListener
  {
    private static final long serialVersionUID = 10200L;
    protected final List imageAreaHyperlinks;

    public ImageMapPanel(Rectangle paramJRImageMapRenderer, JRImageMapRenderer arg3)
    {
      try
      {
      
        this.imageAreaHyperlinks = ((JRImageMapRenderer) arg3).getImageAreaHyperlinks(paramJRImageMapRenderer);
      }
      catch (JRException localJRException)
      {
        throw new JRRuntimeException(localJRException);
      }
      addMouseListener(this);
      addMouseMotionListener(this);
    }

    public String getToolTipText(MouseEvent paramMouseEvent)
    {
      String str = null;
      JRPrintImageAreaHyperlink localJRPrintImageAreaHyperlink = getImageMapArea(paramMouseEvent);
      if (localJRPrintImageAreaHyperlink != null)
        str = JRViewer300.this.getHyperlinkTooltip(localJRPrintImageAreaHyperlink.getHyperlink());
      if (str == null)
        str = super.getToolTipText(paramMouseEvent);
      return str;
    }

    public void mouseDragged(MouseEvent paramMouseEvent)
    {
      JRViewer300.this.pnlLinksMouseDragged(paramMouseEvent);
    }

    public void mouseMoved(MouseEvent paramMouseEvent)
    {
      JRPrintImageAreaHyperlink localJRPrintImageAreaHyperlink = getImageMapArea(paramMouseEvent);
      if ((localJRPrintImageAreaHyperlink != null) && (localJRPrintImageAreaHyperlink.getHyperlink().getHyperlinkType() != 1))
        paramMouseEvent.getComponent().setCursor(Cursor.getPredefinedCursor(12));
      else
        paramMouseEvent.getComponent().setCursor(Cursor.getDefaultCursor());
    }

    protected JRPrintImageAreaHyperlink getImageMapArea(MouseEvent paramMouseEvent)
    {
      return getImageMapArea((int)(paramMouseEvent.getX() / JRViewer300.this.realZoom), (int)(paramMouseEvent.getY() / JRViewer300.this.realZoom));
    }

    protected JRPrintImageAreaHyperlink getImageMapArea(int paramInt1, int paramInt2)
    {
      Object localObject = null;
      if (this.imageAreaHyperlinks != null)
      {
        ListIterator localListIterator = this.imageAreaHyperlinks.listIterator(this.imageAreaHyperlinks.size());
        while ((localObject == null) && (localListIterator.hasPrevious()))
        {
          JRPrintImageAreaHyperlink localJRPrintImageAreaHyperlink = (JRPrintImageAreaHyperlink)localListIterator.previous();
          if (localJRPrintImageAreaHyperlink.getArea().containsPoint(paramInt1, paramInt2))
            localObject = localJRPrintImageAreaHyperlink;
        }
      }
      return (JRPrintImageAreaHyperlink) localObject;
    }

    public void mouseClicked(MouseEvent paramMouseEvent)
    {
      JRPrintImageAreaHyperlink localJRPrintImageAreaHyperlink = getImageMapArea(paramMouseEvent);
      if (localJRPrintImageAreaHyperlink != null)
        JRViewer300.this.hyperlinkClicked(localJRPrintImageAreaHyperlink.getHyperlink());
    }

    public void mouseEntered(MouseEvent paramMouseEvent)
    {
    }

    public void mouseExited(MouseEvent paramMouseEvent)
    {
    }

    public void mousePressed(MouseEvent paramMouseEvent)
    {
      paramMouseEvent.getComponent().setCursor(Cursor.getPredefinedCursor(13));
      JRViewer300.this.pnlLinksMousePressed(paramMouseEvent);
    }

    public void mouseReleased(MouseEvent paramMouseEvent)
    {
      paramMouseEvent.getComponent().setCursor(Cursor.getDefaultCursor());
      JRViewer300.this.pnlLinksMouseReleased(paramMouseEvent);
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.util.JRViewer300
 * JD-Core Version:    0.6.0
 */